<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      background: red;
      /* 1. 给父类设置height */
      /* height: 100px; */

      /* 2. 给父类设置overflow:hidden; */
      /* overflow: hidden; */

      /* 4. 给父类设置overflow:auto */
      /* overflow: auto; */
    }

    /* 5. 给父类增加伪类 */
    .box::after {
      content: '';
      clear: both;
      display: block;
      height: 0;
      overflow: hidden;
    }

    /* 3. 增加空标签 */
    .box .clearfix {
      clear: both;
      height: 0;
      overflow: hidden;
    }

    .box .item {
      height: 100px;
      width: 100px;
      background: green;
      margin: 10px;
      float: left;
    }
  </style>
</head>

<body>
  <div class="box">
    <div class="item"></div>
    <div class="item"></div>
    <!-- <div class="clearfix"></div> -->
  </div>
</body>

</html>